home *** CD-ROM | disk | FTP | other *** search
- /*
- * GetUserIdentity.c
- *
- * Copyright © 1993, Apple Computer Inc.
- * All rights reserved.
- *
- * This function initializes AOCE in an application context.
- * If it returns successfully, it stores the user identity
- * in the supplied variable.
- */
-
- #include <GestaltEqu.h>
- #include <OCE.h>
- #include <OCEAuthDir.h>
- #include <OCEErrors.h>
- #include <OCEStandardDirectory.h>
- #define TRUE 1
- #define FALSE 0
-
- OSErr GetUserIdentity(
- AuthIdentity *userIdentity
- );
-
- /*
- * Get the user's local identity. On success, the identity is
- * stored in the specified location. The only expected error
- * is userCanceledErr, which probably means "just exit the
- * application." Other errors should be displayed.
- */
- OSErr
- GetUserIdentity(
- AuthIdentity *userIdentity
- )
- {
- long gestaltResponse;
- SDPIdentityKind selectedKind;
- AuthParamBlock authParamBlock;
- OSErr status;
-
- /*
- * Make sure this Macintosh supports AOCE.
- */
- status = Gestalt(gestaltOCEToolboxAttr, &gestaltResponse);
- if (status == noErr
- && (gestaltResponse & gestaltOCETBAvailable) == 0)
- status = kOCEToolboxNotOpen;
- if (status == noErr) {
- /*
- * OCE Setup: get the user's local authentication identity. If it's
- * already set, we can do this silently. If it's not set (the system
- * has just been started), we'll prompt for the user's identity
- * and password.
- *
- * The only expected error is "Cancel" from SDPPromptForIdentity.
- */
- status = AuthGetLocalIdentity(
- &authParamBlock, /* Parameter block */
- FALSE /* Synchronous */
- );
- }
- if (status == noErr) {
- /*
- * The user identity has already been specified.
- */
- *userIdentity = authParamBlock.getLocalIdentityPB.theLocalIdentity;
- }
- else if (status == kOCELocalAuthenticationFail) {
- /*
- * No user identity has been specified. Ask for the user to specify
- * the local identity.
- */
- status = SDPPromptForID(
- userIdentity, /* AuthIdentity *id */
- NULL, /* Default guest prompt */
- NULL, /* Default specific prompt */
- NULL, /* Default local prompt */
- NULL, /* RString *recordType */
- ( /* SDPIdentityKind permittedKinds */
- kSDPLocalIdentityMask /* Local identity */
- | kSDPSpecificIdentityMask /* or specific identity */
- ),
- &selectedKind, /* SDPIdentityKind *selectedKind */
- NULL, /* RecordID *loginFilter */
- 0 /* SDPLoginFilterKind filterKind */
- );
- }
- else {
- /* AuthGetLocalIdentity is very unhappy. */
- }
- return (status);
- }
-